package com.huaxin.device.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaxin.device.dto.request.AddDeviceModelReqDTO;
import com.huaxin.device.dto.request.UpdateDeviceModelReqDTO;
import com.huaxin.device.models.DeviceModel;
import com.huaxin.device.service.DeviceModelService;
import com.huaxin.hxjwt.entity.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "设备型号")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/deviceModel")
public class DeviceModelController {
    private final DeviceModelService deviceModelService;

    /**
     * 添加设备型号
     *
     * @param in
     * @return
     */
    @Operation(summary = "添加设备型号", description = "添加设备型号")
    @PostMapping("/addDeviceModel")
    public ResponseResult<String> addDeviceModel(@RequestBody @Valid AddDeviceModelReqDTO in) {
        return deviceModelService.addDeviceModel(in);
    }

    /**
     * 删除设备型号
     *
     * @param id
     * @return
     */
    @Operation(summary = "删除设备型号", description = "删除设备型号")
    @GetMapping("/deleteDeviceModel")
    public ResponseResult<String> deleteDeviceModel(@Parameter(description = "设备型号ID", name = "id", required = true) @RequestParam(name = "id", required = true) String id) {
        return deviceModelService.deleteDeviceModel(id);
    }

    /**
     * 修改设备型号
     *
     * @param in
     * @return
     */
    @Operation(summary = "修改设备型号", description = "修改设备型号")
    @PostMapping("/updateDeviceModel")
    public ResponseResult<String> updateDeviceModel(@RequestBody @Valid UpdateDeviceModelReqDTO in) {
        return deviceModelService.updateDeviceModel(in);
    }

    /**
     * 获取设备型号列表
     *
     * @param pageNum    页码
     * @param pageSize   每页数量
     * @param modelCode  设备型号编码
     * @param deviceType 设备类型
     * @return
     */
    @Operation(summary = "获取设备型号列表", description = "获取设备型号列表")
    @GetMapping("/getDeviceModelList")
    public ResponseResult<Page<DeviceModel>> getDeviceModelList(@Parameter(description = "页码", name = "pageNum", required = true) @RequestParam(name = "pageNum", required = true) Integer pageNum,
                                                                @Parameter(description = "每页数量", name = "pageSize", required = true) @RequestParam(name = "pageSize", required = true) Integer pageSize,
                                                                @Parameter(description = "设备型号编码", name = "modelCode") @RequestParam(name = "modelCode", required = false) String modelCode,
                                                                @Parameter(description = "设备类型", name = "deviceType") @RequestParam(name = "deviceType", required = false) String deviceType) {
        return deviceModelService.getDeviceModelList(pageNum, pageSize, modelCode, deviceType);
    }

    /**
     * 获取设备型号详情
     *
     * @param id 设备型号ID
     * @return
     */
    @Operation(summary = "获取设备型号详情", description = "获取设备型号详情")
    @GetMapping("/getDeviceModelDetail")
    public ResponseResult<DeviceModel> getDeviceModelDetail(@Parameter(description = "设备型号ID", name = "id", required = true) @RequestParam(name = "id", required = true) String id) {
        return ResponseResult.ok(deviceModelService.getDeviceModelDetail(id));
    }
}
